<?php
//Registration form
echo '<form name="register" method="post">';
echo '<input type="hidden" name="page" value="register">';
echo $lang['reg_name'] . ' <p><input type="text" name="reg_name"></p><br>';
echo $lang['reg_pass'] . ' <p><input type="password" name="reg_pass"></p><br>';
echo $lang['reg_pass_confirm'] . ' <p><input type="password" name="reg_pass_confirm"></p><br>';
echo $lang['reg_email'] . ' <p><input type="text" name="reg_email"><br></p>';
echo ' <p><input type="submit" value="'.$lang['reg_submit'].'"></p><br>';

if ($_POST) {
//Registration script
if($_POST['reg_name'] && $_POST['reg_pass'] && $_POST['reg_pass_confirm'] && $_POST['reg_email'])
{
	if($_POST['reg_pass'] == $_POST['reg_pass_confirm'])
	{	
	if (cemail($_POST['reg_email'])) {
		$sql = dibi::query("SELECT `id` FROM `users` ORDER BY `id` DESC LIMIT 0, 1");
		$sql = $sql->fetchAll();
		$pass=hash('sha256',$_POST['reg_pass']);
		$date = time();
		$ins = dibi::query("INSERT INTO `users` (`id`, `name`, `pass`, `mail`,`group`, `registrationdate`) VALUES (NULL, %s",$_POST['reg_name'],", %s",$pass,", %s",$_POST['reg_email'],", 1 , %i",$date,")");
	     $insertId = dibi::insertId();
     	echo '<a href="index.php?page=activate&u='.$insertId.'&hash=' . md5($_POST['reg_email']).'">Aktivace</a>';
} else {echo "<script> alert('".$lang['reg_email_bad']."');</script><noscript>".$lang['reg_email_bad']."</noscript>";};
	}
	else
	{
		echo "<script> alert('".$lang['reg_pass_not_match']."');</script><noscript>".$lang['reg_pass_not_match']."</noscript>";
	};
}; };
?>